
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Event Snapshots · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="event-processing.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../architecture-overview/">
            
                <a href="../../architecture-overview/">
            
                    
                    Architecture Overview
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../architecture-overview/ddd-cqrs-concepts.html">
            
                <a href="../../architecture-overview/ddd-cqrs-concepts.html">
            
                    
                    DDD & CQRS Concepts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../architecture-overview/event-sourcing.html">
            
                <a href="../../architecture-overview/event-sourcing.html">
            
                    
                    Event Sourcing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../architecture-overview/event-driven-microservices.html">
            
                <a href="../../architecture-overview/event-driven-microservices.html">
            
                    
                    Event-Driven Microservices
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../axon-server-introduction.html">
            
                <a href="../../axon-server-introduction.html">
            
                    
                    Axon Server
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../release-notes/">
            
                <a href="../../release-notes/">
            
                    
                    Release Notes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../release-notes/rn-axon-framework/">
            
                <a href="../../release-notes/rn-axon-framework/">
            
                    
                    Axon Framework
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="../../release-notes/rn-axon-framework/rn-af-major-releases.html">
            
                <a href="../../release-notes/rn-axon-framework/rn-af-major-releases.html">
            
                    
                    Major Releases
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="../../release-notes/rn-axon-framework/rn-af-minor-releases.html">
            
                <a href="../../release-notes/rn-axon-framework/rn-af-minor-releases.html">
            
                    
                    Minor Releases
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../release-notes/rn-axon-server/">
            
                <a href="../../release-notes/rn-axon-server/">
            
                    
                    Axon Server
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../../release-notes/rn-axon-server/rn-as-major-releases.html">
            
                <a href="../../release-notes/rn-axon-server/rn-as-major-releases.html">
            
                    
                    Major Releases
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="../../release-notes/rn-axon-server/rn-asse-minor-releases.html">
            
                <a href="../../release-notes/rn-axon-server/rn-asse-minor-releases.html">
            
                    
                    Minor Releases Standard Edition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.3" data-path="../../release-notes/rn-axon-server/rn-as-minor-releases.html">
            
                <a href="../../release-notes/rn-axon-server/rn-as-minor-releases.html">
            
                    
                    Minor Releases Enterprise Edition
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../../release-notes/axon-framework-extensions.html">
            
                <a href="../../release-notes/axon-framework-extensions.html">
            
                    
                    Axon Framework Extensions
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">Getting Started</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../getting-started/quick-start.html">
            
                <a href="../../getting-started/quick-start.html">
            
                    
                    Quick Start
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Axon Framework</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../introduction.html">
            
                <a href="../introduction.html">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../messaging-concepts/">
            
                <a href="../messaging-concepts/">
            
                    
                    Messaging Concepts
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../messaging-concepts/anatomy-message.html">
            
                <a href="../messaging-concepts/anatomy-message.html">
            
                    
                    Anatomy of a Message
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../messaging-concepts/message-correlation.html">
            
                <a href="../messaging-concepts/message-correlation.html">
            
                    
                    Message Correlation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="../messaging-concepts/message-intercepting.html">
            
                <a href="../messaging-concepts/message-intercepting.html">
            
                    
                    Message Intercepting
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="../messaging-concepts/supported-parameters-annotated-handlers.html">
            
                <a href="../messaging-concepts/supported-parameters-annotated-handlers.html">
            
                    
                    Supported Parameters for Annotated Handlers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="../messaging-concepts/exception-handling.html">
            
                <a href="../messaging-concepts/exception-handling.html">
            
                    
                    Exception Handling
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="../messaging-concepts/unit-of-work.html">
            
                <a href="../messaging-concepts/unit-of-work.html">
            
                    
                    Unit of Work
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../axon-framework-commands/">
            
                <a href="../axon-framework-commands/">
            
                    
                    Commands
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../axon-framework-commands/modeling/">
            
                <a href="../axon-framework-commands/modeling/">
            
                    
                    Modeling
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1.1" data-path="../axon-framework-commands/modeling/aggregate.html">
            
                <a href="../axon-framework-commands/modeling/aggregate.html">
            
                    
                    Aggregate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.1.2" data-path="../axon-framework-commands/modeling/multi-entity-aggregates.html">
            
                <a href="../axon-framework-commands/modeling/multi-entity-aggregates.html">
            
                    
                    Multi-Entity Aggregates
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.1.3" data-path="../axon-framework-commands/modeling/state-stored-aggregates.html">
            
                <a href="../axon-framework-commands/modeling/state-stored-aggregates.html">
            
                    
                    State Stored Aggregates
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.1.4" data-path="../axon-framework-commands/modeling/aggregate-creation-from-another-aggregate.html">
            
                <a href="../axon-framework-commands/modeling/aggregate-creation-from-another-aggregate.html">
            
                    
                    Aggregate Creation from another Aggregate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.1.5" data-path="../axon-framework-commands/modeling/aggregate-polymorphism.html">
            
                <a href="../axon-framework-commands/modeling/aggregate-polymorphism.html">
            
                    
                    Aggregate Polymorphism
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.1.6" data-path="../axon-framework-commands/modeling/conflict-resolution.html">
            
                <a href="../axon-framework-commands/modeling/conflict-resolution.html">
            
                    
                    Conflict Resolution
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../axon-framework-commands/command-dispatchers.html">
            
                <a href="../axon-framework-commands/command-dispatchers.html">
            
                    
                    Command Dispatchers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="../axon-framework-commands/command-handlers.html">
            
                <a href="../axon-framework-commands/command-handlers.html">
            
                    
                    Command Handlers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="../axon-framework-commands/infrastructure.html">
            
                <a href="../axon-framework-commands/infrastructure.html">
            
                    
                    Infrastructure
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.5" data-path="../axon-framework-commands/configuration.html">
            
                <a href="../axon-framework-commands/configuration.html">
            
                    
                    Configuration
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../events/">
            
                <a href="../events/">
            
                    
                    Events
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.4.1" data-path="../events/event-dispatchers.html">
            
                <a href="../events/event-dispatchers.html">
            
                    
                    Event Dispatchers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.2" data-path="../events/event-handlers.html">
            
                <a href="../events/event-handlers.html">
            
                    
                    Event Handlers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.3" data-path="../events/event-processors/">
            
                <a href="../events/event-processors/">
            
                    
                    Event Processors
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.4.3.1" data-path="../events/event-processors/subscribing.html">
            
                <a href="../events/event-processors/subscribing.html">
            
                    
                    Subscribing Event Processors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.3.2" data-path="../events/event-processors/streaming.html">
            
                <a href="../events/event-processors/streaming.html">
            
                    
                    Streaming Event Processors
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4.4" data-path="../events/event-bus-and-event-store.html">
            
                <a href="../events/event-bus-and-event-store.html">
            
                    
                    Event Bus & Event Store
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.5" data-path="../events/event-versioning.html">
            
                <a href="../events/event-versioning.html">
            
                    
                    Event Versioning
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.6" data-path="../events/event-serialization.html">
            
                <a href="../events/event-serialization.html">
            
                    
                    Event Serialization
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../queries/">
            
                <a href="../queries/">
            
                    
                    Queries
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.5.1" data-path="../queries/query-processing.html">
            
                <a href="../queries/query-processing.html">
            
                    
                    Query Processing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.2" data-path="../queries/query-dispatchers.html">
            
                <a href="../queries/query-dispatchers.html">
            
                    
                    Query Dispatchers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.3" data-path="../queries/query-handlers.html">
            
                <a href="../queries/query-handlers.html">
            
                    
                    Query Handlers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.4" data-path="../queries/implementations.html">
            
                <a href="../queries/implementations.html">
            
                    
                    Implementations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.5" data-path="../queries/configuration.html">
            
                <a href="../queries/configuration.html">
            
                    
                    Configuration
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../sagas/">
            
                <a href="../sagas/">
            
                    
                    Sagas
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.6.1" data-path="../sagas/implementation.html">
            
                <a href="../sagas/implementation.html">
            
                    
                    Implementation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.2" data-path="../sagas/associations.html">
            
                <a href="../sagas/associations.html">
            
                    
                    Associations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.3" data-path="../sagas/infrastructure.html">
            
                <a href="../sagas/infrastructure.html">
            
                    
                    Infrastructure
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../deadlines/">
            
                <a href="../deadlines/">
            
                    
                    Deadlines
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="../deadlines/deadline-managers.html">
            
                <a href="../deadlines/deadline-managers.html">
            
                    
                    Deadline Managers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.2" data-path="../deadlines/event-schedulers.html">
            
                <a href="../deadlines/event-schedulers.html">
            
                    
                    Event Schedulers
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="../testing/">
            
                <a href="../testing/">
            
                    
                    Testing
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.8.1" data-path="../testing/commands-events.html">
            
                <a href="../testing/commands-events.html">
            
                    
                    Commands / Events
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.2" data-path="../testing/sagas-1.html">
            
                <a href="../testing/sagas-1.html">
            
                    
                    Sagas
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="./">
            
                <a href="./">
            
                    
                    Tuning
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="3.9.1" data-path="event-snapshots.html">
            
                <a href="event-snapshots.html">
            
                    
                    Event Snapshots
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.9.2" data-path="event-processing.html">
            
                <a href="event-processing.html">
            
                    
                    Event Processing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.9.3" data-path="command-processing.html">
            
                <a href="command-processing.html">
            
                    
                    Command Processing
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="../monitoring-and-metrics.html">
            
                <a href="../monitoring-and-metrics.html">
            
                    
                    Monitoring and Metrics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="../spring-boot-integration.html">
            
                <a href="../spring-boot-integration.html">
            
                    
                    Spring Boot Integration
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="../modules.html">
            
                <a href="../modules.html">
            
                    
                    Modules
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Axon Server</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../axon-server/introduction.html">
            
                <a href="../../axon-server/introduction.html">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../../axon-server/installation/">
            
                <a href="../../axon-server/installation/">
            
                    
                    Installation
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.1" data-path="../../axon-server/installation/local-installation/">
            
                <a href="../../axon-server/installation/local-installation/">
            
                    
                    Local Installation
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.1.1" data-path="../../axon-server/installation/local-installation/axon-server-se.html">
            
                <a href="../../axon-server/installation/local-installation/axon-server-se.html">
            
                    
                    Axon Server SE
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.1.2" data-path="../../axon-server/installation/local-installation/axon-server-ee.html">
            
                <a href="../../axon-server/installation/local-installation/axon-server-ee.html">
            
                    
                    Axon Server EE
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2.2" data-path="../../axon-server/installation/docker-k8s/">
            
                <a href="../../axon-server/installation/docker-k8s/">
            
                    
                    Docker / K8s
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.2.1" data-path="../../axon-server/installation/docker-k8s/axon-server-se.html">
            
                <a href="../../axon-server/installation/docker-k8s/axon-server-se.html">
            
                    
                    Axon Server SE
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.2.2" data-path="../../axon-server/installation/docker-k8s/axon-server-ee.html">
            
                <a href="../../axon-server/installation/docker-k8s/axon-server-ee.html">
            
                    
                    Axon Server EE
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../../axon-server/administration/">
            
                <a href="../../axon-server/administration/">
            
                    
                    Administration
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.1" data-path="../../axon-server/administration/admin-configuration/">
            
                <a href="../../axon-server/administration/admin-configuration/">
            
                    
                    Configuration
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.1.1" data-path="../../axon-server/administration/admin-configuration/configuration.html">
            
                <a href="../../axon-server/administration/admin-configuration/configuration.html">
            
                    
                    System Properties
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.1.2" data-path="../../axon-server/administration/admin-configuration/command-line-interface.html">
            
                <a href="../../axon-server/administration/admin-configuration/command-line-interface.html">
            
                    
                    Command Line Interface
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.1.3" data-path="../../axon-server/administration/admin-configuration/rest-api.html">
            
                <a href="../../axon-server/administration/admin-configuration/rest-api.html">
            
                    
                    REST API
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.3.2" data-path="../../axon-server/administration/monitoring/">
            
                <a href="../../axon-server/administration/monitoring/">
            
                    
                    Monitoring
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.2.1" data-path="../../axon-server/administration/monitoring/actuator-endpoints.html">
            
                <a href="../../axon-server/administration/monitoring/actuator-endpoints.html">
            
                    
                    Actuator Endpoints
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.2.2" data-path="../../axon-server/administration/monitoring/grpc-metrics.html">
            
                <a href="../../axon-server/administration/monitoring/grpc-metrics.html">
            
                    
                    gRPC Metrics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.2.3" data-path="../../axon-server/administration/monitoring/heartbeat-monitoring.html">
            
                <a href="../../axon-server/administration/monitoring/heartbeat-monitoring.html">
            
                    
                    Heartbeat Monitoring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.3.3" data-path="../../axon-server/administration/clustering.html">
            
                <a href="../../axon-server/administration/clustering.html">
            
                    
                    Clusters
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.4" data-path="../../axon-server/administration/replication-groups.html">
            
                <a href="../../axon-server/administration/replication-groups.html">
            
                    
                    Replication Groups
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.5" data-path="../../axon-server/administration/multi-context.html">
            
                <a href="../../axon-server/administration/multi-context.html">
            
                    
                    Multi-Context
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.6" data-path="../../axon-server/administration/tagging.html">
            
                <a href="../../axon-server/administration/tagging.html">
            
                    
                    Tagging
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.7" data-path="../../axon-server/administration/backup-and-messaging-only-nodes.html">
            
                <a href="../../axon-server/administration/backup-and-messaging-only-nodes.html">
            
                    
                    Backup and Messaging-only Nodes
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.8" data-path="../../axon-server/administration/backups.html">
            
                <a href="../../axon-server/administration/backups.html">
            
                    
                    Backups
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.9" data-path="../../axon-server/administration/recovery.html">
            
                <a href="../../axon-server/administration/recovery.html">
            
                    
                    Recovery
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.10" data-path="../../axon-server/administration/plugins.html">
            
                <a href="../../axon-server/administration/plugins.html">
            
                    
                    Plugins
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.11" data-path="../../axon-server/administration/error-codes.html">
            
                <a href="../../axon-server/administration/error-codes.html">
            
                    
                    Error Codes
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../../axon-server/security/">
            
                <a href="../../axon-server/security/">
            
                    
                    Security
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.4.1" data-path="../../axon-server/security/ssl.html">
            
                <a href="../../axon-server/security/ssl.html">
            
                    
                    SSL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.2" data-path="../../axon-server/security/access-control.html">
            
                <a href="../../axon-server/security/access-control.html">
            
                    
                    Access Control
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.3" data-path="../../axon-server/security/access-control-se.html">
            
                <a href="../../axon-server/security/access-control-se.html">
            
                    
                    Access Control - Standard Edition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.4" data-path="../../axon-server/security/access-control-ee.html">
            
                <a href="../../axon-server/security/access-control-ee.html">
            
                    
                    Access Control - Enterprise Edition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.5" data-path="../../axon-server/security/access-control-clients.html">
            
                <a href="../../axon-server/security/access-control-clients.html">
            
                    
                    Access Control - Client Applications
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.6" data-path="../../axon-server/security/access-control-cli.html">
            
                <a href="../../axon-server/security/access-control-cli.html">
            
                    
                    Access Control - CLI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.7" data-path="../../axon-server/security/access-control-api.html">
            
                <a href="../../axon-server/security/access-control-api.html">
            
                    
                    Access Control - API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.8" data-path="../../axon-server/security/access-control-ldap.html">
            
                <a href="../../axon-server/security/access-control-ldap.html">
            
                    
                    Access Control - LDAP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4.9" data-path="../../axon-server/security/access-control-oauth2.html">
            
                <a href="../../axon-server/security/access-control-oauth2.html">
            
                    
                    Access Control - OAuth 2.0
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../../axon-server/performance/">
            
                <a href="../../axon-server/performance/">
            
                    
                    Performance
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.5.1" data-path="../../axon-server/performance/tuning-event-processing.html">
            
                <a href="../../axon-server/performance/tuning-event-processing.html">
            
                    
                    Event Segments
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5.2" data-path="../../axon-server/performance/flow-control.html">
            
                <a href="../../axon-server/performance/flow-control.html">
            
                    
                    Flow Control
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="../../axon-server/migration/">
            
                <a href="../../axon-server/migration/">
            
                    
                    Migration
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.6.1" data-path="../../axon-server/migration/standard-to-enterprise-edition.html">
            
                <a href="../../axon-server/migration/standard-to-enterprise-edition.html">
            
                    
                    Standard to Enterprise Edition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6.2" data-path="../../axon-server/migration/non-axon-server-to-axon-server.html">
            
                <a href="../../axon-server/migration/non-axon-server-to-axon-server.html">
            
                    
                    Non-Axon Server to Axon Server
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">Extensions</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../../extensions/spring-amqp.html">
            
                <a href="../../extensions/spring-amqp.html">
            
                    
                    Spring AMQP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../../extensions/jgroups.html">
            
                <a href="../../extensions/jgroups.html">
            
                    
                    JGroups
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../../extensions/kafka.html">
            
                <a href="../../extensions/kafka.html">
            
                    
                    Kafka
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../../extensions/kotlin.html">
            
                <a href="../../extensions/kotlin.html">
            
                    
                    Kotlin
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../../extensions/mongo.html">
            
                <a href="../../extensions/mongo.html">
            
                    
                    Mongo
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../../extensions/reactor/reactor.html">
            
                <a href="../../extensions/reactor/reactor.html">
            
                    
                    Reactor
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.6.1" data-path="../../extensions/reactor/reactive-gateways/reactive-gateways.html">
            
                <a href="../../extensions/reactor/reactive-gateways/reactive-gateways.html">
            
                    
                    Reactor Gateways
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="../../extensions/spring-cloud.html">
            
                <a href="../../extensions/spring-cloud.html">
            
                    
                    Spring Cloud
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="../../extensions/tracing.html">
            
                <a href="../../extensions/tracing.html">
            
                    
                    Tracing
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Appendices</li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../../appendices/rdbms-tuning.html">
            
                <a href="../../appendices/rdbms-tuning.html">
            
                    
                    A. RDBMS Tuning
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../../appendices/message-handler-tuning/">
            
                <a href="../../appendices/message-handler-tuning/">
            
                    
                    B. Message Handler Tuning
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.2.1" data-path="../../appendices/message-handler-tuning/parameter-resolvers.html">
            
                <a href="../../appendices/message-handler-tuning/parameter-resolvers.html">
            
                    
                    Parameter Resolvers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2.2" data-path="../../appendices/message-handler-tuning/handler-enhancers.html">
            
                <a href="../../appendices/message-handler-tuning/handler-enhancers.html">
            
                    
                    Handler Enhancers
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="../../appendices/meta-annotations.html">
            
                <a href="../../appendices/meta-annotations.html">
            
                    
                    C. Meta Annotations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="../../appendices/identifier-generation.html">
            
                <a href="../../appendices/identifier-generation.html">
            
                    
                    D. Identifier Generation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="../../appendices/query-reference.html">
            
                <a href="../../appendices/query-reference.html">
            
                    
                    E. Axon Server Query Language
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Event Snapshots</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="event-snapshots">Event Snapshots</h1>
<h2 id="snapshotting">Snapshotting</h2>
<p>When aggregates live for a long time, and their state constantly changes, they will generate a large amount of events. Having to load all these events in to rebuild an aggregate&apos;s state may have a big performance impact. The snapshot event is a domain event with a special purpose: it summarises an arbitrary amount of events into a single one. By regularly creating and storing a snapshot event, the event store does not have to return long lists of events. Just the latest snapshot events and all events that occurred after the snapshot was made.</p>
<p>For example, items in stock tend to change quite often. Each time an item is sold, an event reduces the stock by one. Every time a shipment of new items comes in, the stock is incremented by some larger number. If you sell a hundred items each day, you will produce at least 100 events per day. After a few days, your system will spend too much time reading in all these events just to find out whether it should raise an &quot;ItemOutOfStockEvent&quot;. A single snapshot event could replace a lot of these events, just by storing the current number of items in stock.</p>
<h3 id="creating-a-snapshot">Creating a snapshot</h3>
<p>Snapshot creation can be triggered by a number of factors, for example: the number of events created since the last snapshot, the time to initialize an aggregate exceeds a certain threshold, time-based, etc. Currently, Axon provides a mechanism that allows you to trigger snapshots based on an event count threshold.</p>
<p>The definition of when snapshots should be created, is provided by the <code>SnapshotTriggerDefinition</code> interface.</p>
<p>The <code>EventCountSnapshotTriggerDefinition</code> provides the mechanism to trigger snapshot creation when the number of events needed to load an aggregate exceeds a certain threshold. If the number of events needed to load an aggregate exceeds a certain configurable threshold, the trigger tells a <code>Snapshotter</code> to create a snapshot for the aggregate.</p>
<p>The snapshot trigger is configured on an event sourcing repository and has a number of properties that allow you to tweak triggering:</p>
<ul>
<li><code>Snapshotter</code> sets the actual snapshotter instance, responsible for creating and storing the actual snapshot event;</li>
<li><code>Trigger</code> sets the threshold at which to trigger snapshot creation;</li>
</ul>
<p>A <code>Snapshotter</code> is responsible for the actual creation of a snapshot. Typically, snapshotting is a process that should disturb the operational processes as little as possible. Therefore, it is recommended to run the snapshotter in a different thread. The <code>Snapshotter</code> interface declares a single method: <code>scheduleSnapshot()</code>, which takes the aggregate&apos;s type and identifier as parameters.</p>
<p>Axon provides the <code>AggregateSnapshotter</code>, which creates and stores <code>AggregateSnapshot</code> instances. This is a special type of snapshot, since it contains the actual aggregate instance within it. The repositories provided by Axon are aware of this type of snapshot, and will extract the aggregate from it, instead of instantiating a new one. All events loaded after the snapshot events are streamed to the extracted aggregate instance.</p>
<blockquote>
<p><strong>Serializing a Snapshot Event</strong></p>
<p>Do make sure the <code>Serializer</code> instance you use (which defaults to the <code>XStreamSerializer</code>) is capable of serializing your aggregate. 
The <code>XStreamSerializer</code> requires you to use either a Hotspot JVM, or your aggregate must either have an accessible default constructor or implement the <code>Serializable</code> interface.</p>
</blockquote>
<p>The <code>AbstractSnapshotter</code> provides a basic set of properties that allow you to tweak the way snapshots are created:</p>
<ul>
<li><code>EventStore</code> sets the event store, which is used to load past events and store the snapshots. This event store must implement the <code>SnapshotEventStore</code> interface.</li>
<li><code>Executor</code> sets the executor, such as a <code>ThreadPoolExecutor</code> that will provide the thread to process actual snapshot creation. By default, snapshots are created in the thread that calls the <code>scheduleSnapshot()</code> method, which is generally not recommended for production.</li>
</ul>
<p>The <code>AggregateSnapshotter</code> provides one more property:</p>
<ul>
<li><code>AggregateFactories</code> is the property that allows you to set the factories that will create instances of your aggregates. 
Configuring multiple aggregate factories allows you to use a single <code>Snapshotter</code> to create snapshots for a variety of aggregate types. 
The <code>EventSourcingRepository</code> implementations and the <code>AggregateConfiguration</code> provide access to the <code>AggregateFactory</code> being used for a given Aggregate.
Both provide the factory through the <code>EventSourcingRepository#getAggregateFactory</code> and <code>AggregateConfiguration#aggregateFactory</code> methods respectively.<br>The result from either can be used to configure the same aggregate factories in the <code>Snapshotter</code> as the ones used by the Aggregate.</li>
</ul>
<blockquote>
<p><strong>Snapshotter Configuration</strong></p>
<p>If you use an executor that executes snapshot creation in another thread, make sure you configure the correct transaction management for your underlying event store, if necessary.</p>
<p>For both non-Spring and Spring users a default <code>Snapshotter</code> is provided.
The former uses the Configuration API to provide a default <code>AggregateSnapshotter</code>, retrieving the aggregate factories from the registered Aggregates / <code>AggregateConfiguration</code>s.
Spring uses a <code>SpringAggregateSnapshotter</code>, which will automatically looks up the right <code>AggregateFactory</code> instances from the application context when a snapshot needs to be created.</p>
<p>The <code>@Revision</code> annotation has a dedicated, automatically configured <code>SnapshotFilter</code> implementation. This implementation is used to filter out non-matching snapshots from the <code>Repository</code>&apos;s loading process. 
So when the <code>@Revision</code> annotation is used on an aggregate the snapshots will be filtered out automatically. </p>
</blockquote>
<p> tabs 
 tab title=&quot;Axon Configuration API&quot; </p>
<pre><code class="lang-java">AggregateConfigurer&lt;GiftCard&gt; giftCardConfigurer =
        AggregateConfigurer.defaultConfiguration(GiftCard.class)
                           .configureSnapshotTrigger(config -&gt; <span class="hljs-keyword">new</span> EventCountSnapshotTriggerDefinition(
                                   config.snapshotter(), <span class="hljs-number">500</span>
                           ));
Configurer configurer = DefaultConfigurer.defaultConfiguration()
                                         .configureAggregate(giftCardConfigurer);
</code></pre>
<p> endtab </p>
<p> tab title=&quot;Spring Boot AutoConfiguration&quot; 
It is possible to define a custom <code>SnapshotTriggerDefinition</code> for an aggregate as a Spring bean. 
In order to tie the <code>SnapshotTriggerDefinition</code> bean to an aggregate, use the <code>snapshotTriggerDefinition</code> attribute on <code>@Aggregate</code> annotation. 
Listing below shows how to define a custom <code>EventCountSnapshotTriggerDefinition</code> which will take a snapshot every 500 events.</p>
<p>Note that a <code>Snapshotter</code> instance, if not explicitly defined as a bean already, will be automatically configured for you. 
This means you can simply pass the <code>Snapshotter</code> as a parameter to your <code>SnapshotTriggerDefinition</code>.</p>
<pre><code class="lang-java"><span class="hljs-meta">@Bean</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> SnapshotTriggerDefinition <span class="hljs-title">giftCardSnapshotTrigger</span><span class="hljs-params">(Snapshotter snapshotter)</span> </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> EventCountSnapshotTriggerDefinition(snapshotter, <span class="hljs-number">500</span>);
}

...

<span class="hljs-meta">@Aggregate</span>(snapshotTriggerDefinition = <span class="hljs-string">&quot;giftCardSnapshotTrigger&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GiftCard</span> </span>{...}
</code></pre>
<p> endtab 
 endtabs </p>
<h3 id="storing-snapshot-events">Storing Snapshot Events</h3>
<p>When a snapshot is stored in the event store, it will automatically use that snapshot to summarize all prior events and return it in their place. All event store implementations allow for concurrent creation of snapshots. This means they allow snapshots to be stored while another process is adding events for the same aggregate. This allows the snapshotting process to run as a separate process altogether.</p>
<blockquote>
<p><strong>Snapshots as a replacement of your events?</strong></p>
<p>Normally, you can archive all events once they are part of a snapshot event. 
Snapshotted events will never be read in again by the event store in regular operational scenarios. 
However, if you want to be able to reconstruct an aggregate state prior to the moment the snapshot was created, you must keep the events up to that date.</p>
</blockquote>
<p>Axon provides a special type of snapshot event: the <code>AggregateSnapshot</code>, which stores an entire aggregate as a snapshot. The motivation is simple: your aggregate should only contain the state relevant to take business decisions. This is exactly the information you want captured in a snapshot. All event sourcing repositories provided by Axon recognize the <code>AggregateSnapshot</code>, and will extract the aggregate from it. Beware that using this snapshot event requires that the event serialization mechanism needs to be able to serialize the aggregate.</p>
<h3 id="filtering-snapshot-events">Filtering Snapshot Events</h3>
<p>When enabling snapshotting, several snapshots would be stored per Aggregate instance in the event store.
At a certain stage, some of these snapshot events are no longer being used by the application as newer versions took their place.
Especially if these snapshot events portray an old format of the aggregate by using the <code>AggregateSnapshot</code> event would it be smart to no longer load these.</p>
<p>You could take the stance of dropping all the snapshots which are stored (for a given aggregate type), but this means snapshots will be recreated with a 100% certainty.
It is also possible to filter out snapshot events when reading your Aggregate from the event store.
To that end, a <code>SnapshotFilter</code> can be defined per Aggregate type or for the entire <code>EventStore</code>.</p>
<p>The <code>SnapshotFilter</code> is a functional interface, providing two main operations: <code>allow(DomainEventData&lt;?)</code> and <code>combine(SnapshotFilter)</code>.
The former provides the <code>DomainEventData</code> which reflects the snapshot events. 
The latter allows combining several <code>SnapshotFilter</code>s together.</p>
<p>The following snippets show how to configure a <code>SnapshotFilter</code>: </p>
<p> tabs 
 tab title=&quot;Axon Configuration API&quot; </p>
<pre><code class="lang-java">SnapshotFilter giftCardSnapshotFilter = snapshotData -&gt; <span class="hljs-comment">/* allow or disallow this snapshotData */</span>;

AggregateConfigurer&lt;GiftCard&gt; giftCardConfigurer = 
        AggregateConfigurer.defaultConfiguration(GiftCard.class)
                           .configureSnapshotFilter(config -&gt; giftCardSnapshotFilter);
Configurer configurer = DefaultConfigurer.defaultConfiguration()
                                         .configureAggregate(giftCardConfigurer);
</code></pre>
<p> endtab </p>
<p> tab title=&quot;Spring Boot AutoConfiguration&quot; 
It is possible to define a custom <code>SnapshotFilter</code> for an aggregate as a Spring bean. 
In order to tie the <code>SnapshotFilter</code> bean to an aggregate, use the <code>snapshotFilter</code> attribute on <code>@Aggregate</code> annotation. </p>
<pre><code class="lang-java"><span class="hljs-meta">@Bean</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> SnapshotFilter <span class="hljs-title">giftCardSnapshotFilter</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> snapshotData -&gt; <span class="hljs-comment">/* allow or disallow this snapshotData */</span>;
}

...

<span class="hljs-meta">@Aggregate</span>(snapshotFilter = <span class="hljs-string">&quot;giftCardSnapshotFilter&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GiftCard</span> </span>{...}
</code></pre>
<p> endtab 
 endtabs </p>
<h3 id="initializing-an-aggregate-based-on-a-snapshot-event">Initializing an Aggregate based on a Snapshot Event</h3>
<p>A snapshot event is an event like any other. That means a snapshot event is handled just like any other domain event. When using annotations to demarcate event handlers (<code>@EventHandler</code>), you can annotate a method that initializes full aggregate state based on a snapshot event. The code sample below shows how snapshot events are treated like any other domain event within the aggregate.</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyAggregate</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">AbstractAnnotatedAggregateRoot</span> </span>{

    <span class="hljs-comment">// ... </span>

    <span class="hljs-meta">@EventHandler</span>
    <span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">handleSomeStateChangeEvent</span><span class="hljs-params">(MyDomainEvent event)</span> </span>{
        <span class="hljs-comment">// ...</span>
    }

    <span class="hljs-meta">@EventHandler</span>
    <span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">applySnapshot</span><span class="hljs-params">(MySnapshotEvent event)</span> </span>{
        <span class="hljs-comment">// the snapshot event should contain all relevant state</span>
        <span class="hljs-keyword">this</span>.someState = event.someState;
        <span class="hljs-keyword">this</span>.otherState = event.otherState;
    }
}
</code></pre>
<p>There is one type of snapshot event that is treated differently: the <code>AggregateSnapshot</code>. This type of snapshot event contains the actual aggregate. The aggregate factory recognizes this type of event and extracts the aggregate from the snapshot. Then, all other events are re-applied to the extracted snapshot. That means aggregates never need to be able to deal with <code>AggregateSnapshot</code> instances themselves.</p>
<h2 id="caching">Caching</h2>
<p>A well-designed command handling module should pose no problems when implementing caching.
Especially when using event sourcing, loading an aggregate from an Event Store can be an expensive operation.
With a properly configured cache in place, loading an aggregate can be converted into a pure in-memory process.</p>
<p>To that end, Axon allows the configuration of a <code>Cache</code> object.
The framework currently provides several implementations to choose from:</p>
<ul>
<li><code>WeakReferenceCache</code> - An in-memory cache solution. In most scenarios, this is a good start.</li>
<li><code>EhCacheAdapter</code> -
An <code>AbstractCacheAdapter</code>, wrapping <a href="https://www.ehcache.org/" target="_blank">EhCache</a> into a usable solution for Axon.</li>
<li><code>JCacheAdapter</code> -
An <code>AbstractCacheAdapter</code>, wrapping <a href="https://www.javadoc.io/doc/javax.cache/cache-api/1.0.0/index.html" target="_blank">JCache</a> into a usable solution for Axon.</li>
<li><code>AbstractCacheAdapter</code> - Abstract implementation towards supporting Axon&apos;s <code>Cache</code> API.
Helpful in writing an adapter for a cache implementation that Axon does not support out of the box.</li>
</ul>
<p>Before configuring a <code>Cache</code>, please consider the following guidelines.
They will help you get the most out of your caching solution:</p>
<ul>
<li><p><strong>Make sure the unit of work never needs to perform a rollback for functional reasons.</strong>
A rollback means that an aggregate has reached an invalid state.
Axon will automatically invalidate the cache entries involved.
The following request will force the aggregate to be reconstructed from its events.
If you use exceptions as a potential (functional) return value, you can configure a <code>RollbackConfiguration</code> on your command bus.
By default, the configuration will roll back the unit of work on unchecked exceptions for command handlers and on all exceptions for event handlers.</p>
</li>
<li><p><strong>All commands for a single aggregate must arrive on the machine with the aggregate in its cache.</strong>
This requirement means that commands should be consistently routed to the same machine for as long as that machine is &quot;healthy.&quot;
Routing commands consistently prevents the cache from going stale.
A hit on a stale cache will cause a command to be executed and fail when events are stored in the event store.
By default, Axon&apos;s distributed command bus components will use consistent hashing to route commands.</p>
</li>
<li><p><strong>Configure a sensible time to live / time to idle.</strong>
By default, caches tend to have a relatively short time to live, a matter of minutes.
For a command handling component with consistent routing, a longer time-to-idle and time-to-live is usually better.
This setting prevents the need to re-initialize an aggregate based on its events because its cache entry expired.
The time-to-live of your cache should match the expected lifetime of your aggregate.</p>
</li>
<li><p><strong>Cache data in-memory.</strong>
For proper optimization, caches should keep data in-memory (and preferably on-heap) for best performance.
This approach prevents the need to (re)serialize aggregates when storing to disk and even off-heap.</p>
</li>
</ul>
<p>To configure a cache for your Aggregates, consider the following snippet:</p>
<p> tabs 
 tab title=&quot;Axon Configuration API&quot; </p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AxonConfig</span> </span>{
    <span class="hljs-comment">// ...</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">configureAggregateWithCache</span><span class="hljs-params">(Configurer configurer)</span> </span>{
        AggregateConfigurer&lt;GiftCard&gt; giftCardConfigurer =
                AggregateConfigurer.defaultConfiguration(GiftCard.class)
                                   .configureCache(config -&gt; <span class="hljs-keyword">new</span> WeakReferenceCache());

        configurer.configureAggregate(giftCardConfigurer);
    }
}
</code></pre>
<p> endtab </p>
<p> tab title=&quot;Spring Boot AutoConfiguration&quot; 
The <code>Aggregate</code> annotation allows specification of the cache bean:</p>
<pre><code class="lang-java"><span class="hljs-meta">@Aggregate</span>(cache = <span class="hljs-string">&quot;giftCardCache&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">GiftCard</span> </span>{
    <span class="hljs-comment">// state, command handlers and event sourcing handlers...</span>
}
</code></pre>
<p>This approach does require the bean name to be present in the Application Context of course:</p>
<pre><code class="lang-java"><span class="hljs-meta">@Configuration</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AxonConfig</span> </span>{
    <span class="hljs-comment">// ...</span>
    <span class="hljs-meta">@Bean</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Cache <span class="hljs-title">giftCardCache</span><span class="hljs-params">()</span> </span>{ 
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> WeakReferenceCache();
    }
}
</code></pre>
<p> endtab 
 endtabs </p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: Tuning">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="event-processing.html" class="navigation navigation-next " aria-label="Next page: Event Processing">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Event Snapshots","level":"3.9.1","depth":2,"next":{"title":"Event Processing","level":"3.9.2","depth":2,"path":"axon-framework/tuning/event-processing.md","ref":"axon-framework/tuning/event-processing.md","articles":[]},"previous":{"title":"Tuning","level":"3.9","depth":1,"path":"axon-framework/tuning/README.md","ref":"axon-framework/tuning/README.md","articles":[{"title":"Event Snapshots","level":"3.9.1","depth":2,"path":"axon-framework/tuning/event-snapshots.md","ref":"axon-framework/tuning/event-snapshots.md","articles":[]},{"title":"Event Processing","level":"3.9.2","depth":2,"path":"axon-framework/tuning/event-processing.md","ref":"axon-framework/tuning/event-processing.md","articles":[]},{"title":"Command Processing","level":"3.9.3","depth":2,"path":"axon-framework/tuning/command-processing.md","ref":"axon-framework/tuning/command-processing.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"axon-framework/tuning/event-snapshots.md","mtime":"2021-09-13T08:33:05.885Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-13T08:33:36.904Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

